/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package game.module.Exploration;
import org.anddev.andengine.engine.camera.Camera;
import org.anddev.andengine.engine.camera.hud.controls.AnalogOnScreenControl;
import org.anddev.andengine.engine.camera.hud.controls.AnalogOnScreenControl.IAnalogOnScreenControlListener;
import org.anddev.andengine.engine.camera.hud.controls.BaseOnScreenControl;
import org.anddev.andengine.entity.scene.Scene;
import org.anddev.andengine.entity.sprite.Sprite;
import org.anddev.andengine.opengl.texture.Texture;
import org.anddev.andengine.opengl.texture.TextureOptions;
import org.anddev.andengine.opengl.texture.region.TextureRegion;
import org.anddev.andengine.opengl.texture.region.TextureRegionFactory;
import org.anddev.andengine.ui.activity.BaseGameActivity;
/**
 *
 * @author John Rice
 */
public class iMapScreen implements game.nm.SceneLoader{
	//varblock-----------------------------------
	private Level currLevel;
	private AnalogOnScreenControl cStick;
	private Sprite jumpButton;
	private final float cStickSensitivity = 20;
	private CharacterRepresentation player;
	//===========================================
	//physics------------------------------------
	//===========================================
	//images-------------------------------------
	private Texture playerT;
	private TextureRegion playerTR;
	private Texture cBaseT;
	private Texture cKnobT;
	private TextureRegion cBaseTR;
	private TextureRegion cKnobTR;
	//===========================================

	public iMapScreen(String levelName){
		currLevel = new Level(levelName);
	}

	public Scene loadScene(){
		return null;
	}

	//from sceneLoader------------
	/**
	 *
	 * This function assumes nothing about the BaseActivity
	 * other than it can accept more textures. It loads the resources it needs
	 * then returns a scene. It is the callers responsibility to do something
	 * with the scene
	 *
	 * @param eng
	 * @return returns a Scene
	 */
	public Scene LoadScene(BaseGameActivity eng, final Camera cam){
		//load in reources------------------
		loadResources(eng);
		//==================================
		//set up the scene------------------
		final Scene scn = currLevel.LoadScene(eng, cam);
		currLevel.placePlayer(player, 0);
		//==================================
		//set up the cStick-----------------
		cStick = new AnalogOnScreenControl(20, 20, cam, cBaseTR, cKnobTR, 0.3f, 200, new IAnalogOnScreenControlListener() {
			@Override
			public void onControlChange(final BaseOnScreenControl pBaseOnScreenControl, final float pValueX, final float pValueY){
				if(pValueX != 0){
					player.transverse(pValueX);
//					cam.setCenter(player.getX(), player.getY());
				}
				if(pValueY < 0) player.jump(-1);
			}
			@Override
			public void onControlClick(final AnalogOnScreenControl pAnalogOnScreenControl){}
		});
		//==================================
		scn.setChildScene(cStick);
		return scn;
	}
	//LoadScene Helpers-----------
	private void loadResources(BaseGameActivity bgm){
		//load up faceman
		playerT = new Texture(32, 32, TextureOptions.BILINEAR_PREMULTIPLYALPHA);
		playerTR = TextureRegionFactory.createFromAsset(playerT, bgm, "gfx/face_box.png", 0, 0);
		bgm.getEngine().getTextureManager().loadTexture(playerT);
		//load up the cstick
		cBaseT = new Texture(128, 128, TextureOptions.BILINEAR_PREMULTIPLYALPHA);
		cBaseTR = TextureRegionFactory.createFromAsset(cBaseT, bgm, "gfx/cBase.png", 0, 0);
		bgm.getEngine().getTextureManager().loadTexture(cBaseT);
		cKnobT = new Texture(64, 64, TextureOptions.BILINEAR_PREMULTIPLYALPHA);
		cKnobTR = TextureRegionFactory.createFromAsset(cKnobT, bgm, "gfx/cKnob.png", 0, 0);
		bgm.getEngine().getTextureManager().loadTexture(cKnobT);
		player = new CharacterRepresentation(playerTR);
	}
	//----------------------------
}
